import { defineStore } from 'pinia'
import { ref } from 'vue'
import {
  getCategory1Service,
  getCategory2Service,
  getCategory3Service
} from '@/apis/product/attr'
import type {
  CategoryResponseData,
  CategoryObj
} from '@/apis/product/attr/type'
export const useCategoryStore = defineStore('admin-category', () => {
  const category1List = ref<CategoryObj[]>([])
  const category2List = ref<CategoryObj[]>([])
  const category3List = ref<CategoryObj[]>([])

  const option1 = ref<number | string>('')
  const getCategory1 = async () => {
    const res: CategoryResponseData = await getCategory1Service()
    category1List.value = res.data
  }
  // 获取二级分类
  const option2 = ref<number | string>('')
  const getCategory2 = async (id: number) => {
    const res: CategoryResponseData = await getCategory2Service(id)
    category2List.value = res.data
  }
  // 获取三级分类
  const option3 = ref<number | string>('')
  const getCategory3 = async (id: number) => {
    const res: CategoryResponseData = await getCategory3Service(id)
    category3List.value = res.data
  }

  return {
    category1List,
    category2List,
    category3List,
    option1,
    option2,
    option3,
    getCategory1,
    getCategory2,
    getCategory3
  }
})
